﻿using FT.Architecture.NHibernate.Factories;
using FT.Architecture.Persistence;
using NHibernate.Tool.hbm2ddl;

namespace FT.Architecture.NHibernate.Persistence
{
    public class PersistenceService : IPersistenceService
    {
        private readonly INHibernateConfigurator nHibernateConfigurator;

        public PersistenceService(INHibernateConfigurator nHibernateConfigurator)
        {
            this.nHibernateConfigurator = nHibernateConfigurator;
        }

        public virtual void BuildPersistence()
        {
            var configuration = nHibernateConfigurator.Configure();
            var export = new SchemaExport(configuration);
            export.Execute(true, true, false);
        }

        public virtual void UpdatePersistence()
        {
            var configuration = nHibernateConfigurator.Configure();
            var export = new SchemaUpdate(configuration);
            export.Execute(true, true);
        }
    }
}
